/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package percussiongenerator.commands;

import java.util.LinkedList;
import java.util.Stack;

/**
 *
 * @author Jannes Plyson
 */
public class CommandHistory {
    private static LinkedList<ICommand> commands = new LinkedList<ICommand>();
    private static int maxCapacity = 50;

    public static void addCommandAndExecute(ICommand command){
        commands.addLast(command);
        if(commands.size() > maxCapacity){
            commands.removeFirst();
        }
        try{
            command.execute();
        }catch(Exception exc){
            exc.printStackTrace();
        };
    }

    public static void undo(){
        if(!commands.isEmpty()){            
            try{
                ICommand command = commands.removeLast();
                command.undo();
            }catch(Exception exc){
                exc.printStackTrace();
            }
        }
    }

    public static void clearHistory(){
        commands.clear();
    }

}
